package com.bocloud.cmp.driver.providers.impl;

import org.springframework.stereotype.Service;

import com.bocloud.cmp.driver.config.Configuration;
import com.bocloud.cmp.driver.providers.LbDriver;
import com.bocloud.cmp.driver.providers.intf.LbProvider;
import com.bocloud.cmp.driver.providers.jd.JdLbDriver;
import com.bocloud.cmp.driver.utils.VendorConverter;
import com.bocloud.cmp.enums.VendorType;
import com.bocloud.cmp.model.Butler;
import com.bocloud.cmp.model.LbModel;
import com.bocloud.common.model.BsmResult;

@Service("lbProvider")
public class LbProviderImpl implements LbProvider {

	@Override
	public BsmResult list(String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			LbDriver driver = new JdLbDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(), region);
			result = driver.list();
			break;
		case ALIYUN:
			break;
		case OPENSTACK:
			break;
		case VMWARE:
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public BsmResult create(String vendor, String region, LbModel lb) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			LbDriver driver = new JdLbDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(), region);
			result = driver.create(lb);
			break;
		case ALIYUN:
			break;
		case OPENSTACK:
			break;
		case VMWARE:
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public BsmResult remove(String lbId, String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			LbDriver driver = new JdLbDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(), region);
			result = driver.remove(lbId);
			break;
		case ALIYUN:
			break;
		case OPENSTACK:
			break;
		case VMWARE:
			break;
		default:
			break;
		}
		return result;
	}

	@Override
	public BsmResult detail(String lbId, String vendor, String region) {
		BsmResult result = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case JDYUN:
			LbDriver driver = new JdLbDriver(butler.getAccessKey(), butler.getSecretKey(), butler.getUrl(), region);
			result = driver.detail(lbId);
			break;
		case ALIYUN:
			break;
		case OPENSTACK:
			break;
		case VMWARE:
			break;
		default:
			break;
		}
		return result;
	}

}
